import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

//element-plus按需引入，防止加载时间过长

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    proxy: {
      '/api': {
        // target: 'https://localhost:8081/', //远程请求地址
        target: 'http://localhost:8080/', //远程请求地址
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      '/bkny': {
        target: 'https://export.bknykf.com/', //远程请求地址
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/bkny/, ''),
      },
      cors: false
    },
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    // viteMockServe()
  ],
  css: {
    preprocessorOptions: {
      less: {
        charset: false,
        additionalData: '@import "./src/assets/style/global.less";'
      }
    }
  },
  //配置编译打包路径
  resolve: {
    alias: {
      '@': resolve('src'),
    }
  },

})

